package stack.era.presentation.hud;

import java.awt.Color;

import stack.era.domain.DomainHome;
import stack.era.presentation.ERAInfoBar;

public class PlayerExperienceBar extends ERAInfoBar {

	private static final long serialVersionUID = 2863386214930469042L;

	private int previousLevelXP, experience, nextLevelXP;

	public PlayerExperienceBar() {
		super(new Color(50, 50, 230));

		this.previousLevelXP = 500;
		this.experience = 550;
		this.nextLevelXP = 600;

		this
				.setToolTipText("<html><body>Experience directly determines your level and how skilled your character is.<br>when you gain enough experience to fill your experience bar,<br>your character will gain a level.</body></html>");
	}

	public void populate() {
		DomainHome domain = DomainHome.getInstance();
		String playerCharName = domain.getWorld().getPlayerCharacterName();
		if (playerCharName != null) {
			this.experience = domain.getCharacter(playerCharName).getXP();
			this.nextLevelXP = domain.getCharacter(playerCharName)
					.getXPRequiredForLevel(
							domain.getCharacter(playerCharName).getLevel() + 1);
			this.previousLevelXP = domain.getCharacter(
					domain.getWorld().getPlayerCharacterName()).getXPRequiredForLevel(
					domain.getCharacter(playerCharName).getLevel());
			this.value = this.experience - this.previousLevelXP;
			this.maxValue = this.nextLevelXP - this.previousLevelXP;
		}
	}

	@Override
	public String getBarString() {
		return this.experience + "/" + this.nextLevelXP;
	}

}
